/*
 * =====================================================================================
 *
 *       Filename:  wav2bmp.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  12/22/2010 03:55:44 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */
#include "bmp.h"
#include "wav.h"
#include <math.h>


int main(int argc, char** argv)
{
    char *fn = argv[1];
    char* bmpfn;
    int w ,h;
    if(argc == 3)
        bmpfn = argv[2];
    else
        bmpfn = "wav2bmp.bmp";
    WAV_HEADER* wavHeader = readWaveFile(fn);
    printWavHeader(wavHeader);  
    w = (int) sqrt(wavHeader->dmDataHeader.dwDataSize); 
    h = wavHeader->dmDataHeader.dwDataSize/w;
    bmp_t* mybmp = create_gray256(w, h);
    bmp_t* mybmp1 = create_gray256(w, h);
    bmp_t* mybmp2 = create_gray256(w, h);
   /* 
    foreachpix(mybmp, ({
                mybmp->data[pixi] = ((unsigned short*)(wavHeader->wavData))[pixi];
                }));
 */
    foreach_gray(a in mybmp, ({
                a = ((unsigned short*)(wavHeader->wavData))[pixi];
                })
            );
    //write_gray256(bmpfn, wavHeader->wavData, w, h);
    write_gray256(bmpfn, mybmp);
}
